import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service 库存组织
 * @date: 2018-7-5


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters } from 'utils/utils';
/**
 * 查询 查询库存组织内容
 * @async
 * @function queryInventoryData -函数名称
 * @param {Object} params - 接口参数
 * @param {String} params.getOrganizationId -租户ID(tenantId)
 * @param {!number} [params.page = 0] -数据页码
 * @param {!number} [params.size = 10] -分页条数
 * @returns {object} fetch Promise
 */

export function queryInventoryData(_x) {
  return _queryInventoryData.apply(this, arguments);
}
/**
 * 新增 库存组织(单条新增)
 * @async
 * @function insertInventoryData -函数名称
 * @param {Object} params -新增参数
 * @param {String} params.getOrganizationId - 租户ID(tenantId)
 * @param {String} params.enabledFlag - 启用标识
 * @param {String} params.organizationCode - 库房组织编码
 * @param {String} params.organizationName - 库房组织名称
 * @param {String} params.ouName - 业务实体名称
 * @param {String} params.ouId -业务实体ID
 * @param {String} params.sourceCode -数据来源
 * @returns {object} fetch Promise
 */

function _queryInventoryData() {
  _queryInventoryData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params.body);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.organizationId, "/inv-organizations"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryInventoryData.apply(this, arguments);
}

export function insertInventoryData(_x2) {
  return _insertInventoryData.apply(this, arguments);
}
/**
 * 更新 库存组织(单条更新)
 * @async
 * @function updateInventoryData -函数名称
 * @param {Object} params - 更新参数
 * @param {String} params.enabledFlag - 启用标识
 * @param {String} params.getOrganizationId - 租户ID(tenantId)
 * @param {String} params.organizationCode - 库房组织编码
 * @param {String} params.organizationName - 库房组织名称
 * @param {String} params.ouName - 业务实体名称
 * @param {String} params.ouId -业务实体ID
 * @param {String} params.sourceCode -数据来源
 * @returns {object} fetch Promise
 */

function _insertInventoryData() {
  _insertInventoryData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.getOrganizationId, "/inv-organizations"), {
              method: 'POST',
              body: params.body
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _insertInventoryData.apply(this, arguments);
}

export function updateInventoryData(_x3) {
  return _updateInventoryData.apply(this, arguments);
}
/**
 * 批量修改/新增 库存组织
 * @function updateAllInventoryData
 * @param {Object} params - 新增参数
 * @param {String} params.enabledFlag - 启用标识
 * @param {String} params.tenantId - 租户ID(tenantId)
 * @param {String} params.organizationCode - 库房组织编码
 * @param {String} params.organizationName - 库房组织名称
 * @param {String} params.ouName - 业务实体名称
 * @param {String} params.ouId -业务实体ID
 * @param {String} params.sourceCode -数据来源
 * @returns {object} fetch Promise
 */

function _updateInventoryData() {
  _updateInventoryData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.getOrganizationId, "/inv-organizations"), {
              method: 'PUT',
              body: params.body
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateInventoryData.apply(this, arguments);
}

export function updateAllInventoryData(_x4) {
  return _updateAllInventoryData.apply(this, arguments);
}
/**
 * 禁用 库存组织
 * @function disableInventory
 * @param {Object} params - 新增参数
 * @param {Object} params.getOrganizationId --租户ID(tenantId)
 * @param {Object} params.invOrganizationId --库存组织ID
 * @returns {object} fetch Promise
 */

function _updateAllInventoryData() {
  _updateAllInventoryData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var body, organizationId;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            body = params.body, organizationId = params.organizationId;
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/inv-organizations/batch-save"), {
              method: 'POST',
              body: body
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateAllInventoryData.apply(this, arguments);
}

export function disableInventory(_x5) {
  return _disableInventory.apply(this, arguments);
}
/**
 * 启用 库存组织
 * @param {Object} params - 新增参数
 * @param {Object} params.getOrganizationId --租户ID
 * @param {Object} params.invOrganizationId --库存组织ID
 * @returns {object} fetch Promise
 */

function _disableInventory() {
  _disableInventory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.getOrganizationId, "/inv-organizations/").concat(params.invOrganizationId, "/disable"), {
              method: 'PATCH',
              body: params.body
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _disableInventory.apply(this, arguments);
}

export function enableInventory(_x6) {
  return _enableInventory.apply(this, arguments);
}

function _enableInventory() {
  _enableInventory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(params.getOrganizationId, "/inv-organizations/").concat(params.invOrganizationId, "/enable"), {
              method: 'PATCH',
              body: params.body
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _enableInventory.apply(this, arguments);
}